<template>
  <div class="list">
    <!-- <top-nav @click.native="toPathMe">返回</top-nav> -->
    <ul class="clearfix">
      <li v-for="(value,index) in dataList" :key="index">
        <img :src="value.photo_url" class="headerImg" @click='picPrev(value.photo_url)'/>
        <div class="title substring"><span class="top_tag" v-if="value.set_top==1">[置顶]</span>{{value.desc==null?'':value.desc}}</div>
        <div class="address substring">{{value.province}}{{value.city==null? "" :value.city}}{{value.area==null?'':value.area}}</div>
        <div class="tel">
          <img src="http://file.rzkeji.com/web/recruit/icon/banner1.png" />
          <span>{{value.phone==null?'':value.phone}}</span>
        </div>
        <div class="detail">
          <div class="classify">{{value.classify_name}}</div>
          <div class="showTime">发布时间:{{value.updated_at}}</div>
        </div>
        <div class="time clearfix">
          <div class="setTop" v-if="type=='show'?true:false" @click="setTop(value.id)">{{value.set_top=='0' ? '未置顶':'置顶中'}}</div>
           <div class="edit" v-if="type=='show'?true:false" @click="edit(value.id)">编辑</div>
           <div class="delete" v-if="type=='show'?true:false" @click="del(value.id)">删除</div>
        </div>
      </li>
    </ul>
  </div>
</template>

<script>
import topNav from '@/components/topNav';
import { ImagePreview } from 'vant';
export default {
  props:['type'],
  data () {
    return {
      classify:''
    }
  },
  components:{
    topNav
  },
  computed:{
    dataList(){
      let res=this.$store.state.modulesInvestment.dataList;
      if(res!=""){
       for(let [index,value] of res.entries()) {
          value.updated_at=value.updated_at.split(' ')[0]   //修改时间的格式 
  　　 }
      }
      return res
    }
  },
  methods:{
    picPrev(e){
        ImagePreview({
        images: [
          e
        ],
        showIndex:false
        })
    },
    async del(value){
      let res=await this.$currency.showModal('','是否删除此纪录')
      if(res){
        var userToken=window.localStorage.getItem('userToken')
        let data=await this.$axios.post('/advert/delMyInvitingAdvert',{user_token:userToken,id:value})
        if(data.data.level=='success'){
          let data1=await this.$axios('/advert/getInvitingAdvert',{params:{user_token:userToken,type:"me"}});
          this.$store.dispatch('setDataList',data1.data.data)
        }else{
          this.$currency.showToast(data1.data.message,3000,'success')
        }
      }
    },
    edit(value){
      this.$router.push(`/me/release?id=${value}`)
    },
    toPathMe(){
      this.$router.push({name:'me'})
    },
    async getClassify(){//获取行业分类
      let res=await this.$axios('advert/getClassify');
      this.classify=res.data.data
    },
    setTop(id){//置顶
        this.$store.dispatch("setAdventType","advent")
      this.$router.push({name:'payment',params:{'id':id}})
    }
  },
  activated(){
    this.getClassify()
  }
}
</script>

<style scoped>
.list{width: 100%;margin-top: 20px;background-color: #F8F8FB;}
.list ul{width: 100%;display: flex;flex-wrap: wrap;}
.list ul li{/*width: 172px;*/ width:46%;height:auto;margin: 20px 0px 2px 10px;border: 1px solid #e4e4e4;background-color: #fff;padding-bottom: 5px;}
.headerImg{width: 100%;height: 196px;}
.title{width:160px;padding-left: 10px; color: #0180CF;line-height: 30px;font-size: 15px;}
.address{width:154px;padding-left: 10px;color: #333;line-height: 30px;font-size: 14px;}
.tel{display: flex;margin:5px 0;}
.tel img{width: 20px;height: 20px;vertical-align: middle;margin:0 10px;}
.tel span{vertical-align:middle;color: #ff0000;font-size: 16px;}
.time{line-height: 30px;color: #999;font-size: 12px;margin: 10px 10px 0px 0px;width: 100%;display: flex;}
.edit{width: 40px;height: 30px;background-color: #76B5FF;margin:0px 5px;text-align: center;color: #fff;border-radius: 5px;}
.delete{width: 40px;height: 30px;background-color: #FF8A83;text-align: center;border-radius: 5px;color: #fff;}
.clearfix{clear:both;overflow: hidden;}

.classify{margin-left:10px;margin-top:5px;margin-bottom: 5px;width: 100%}
.showTime{margin-left:10px;width: 100%}
.detail{
  margin-top:5px;
  color:#999;
  font-size:12px;
  display: flex;
  flex-wrap: wrap;
}
.detail:after{
  content:'';
  display: inline-block;
  clear: both;
  zoom: 1;
}
.setTop{width: 40px;height: 30px;background-color: #38B4DB;text-align: center;border-radius: 5px;color: #fff;margin-left:10px;}
.top_tag{color:red}
</style>
<style>
  .van-dialog{text-align: center !important}
</style>